﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using jaysJourney_v01.Common;
using System.Diagnostics;
using Microsoft.Xna.Framework.Graphics;

namespace jaysJourney_v01.States
{
    public abstract class State
    {
        /**
         * MEMBER VARIABLES
         * */

        // Common

        private String name;
        private StateManager stateManager;
        protected SpriteBatch parentSpriteBatch;

        private int counter = 0; // delaycounter for update on switch

        /**
         * METHODS
         * */

        // Constructor

        public State(String name, StateManager stateManager)
        {        
            this.stateManager = stateManager;
            this.name = name;
            this.parentSpriteBatch = this.stateManager.getMainSB();
        }

        // update this state

        public void stateUpdate(GameTime gameTime)
        {
            if (this.counter > 0) this.counter --;
            if (this.counter <= 0) update(gameTime);
        }

        // draw state
        public void stateDraw(GameTime gameTime)
        {
            draw(gameTime);
        }

        // get name of this state

        public String getName()
        {
            return this.name;
        }

        // get parent statemanager

        public StateManager getStateManager()
        {
            return this.stateManager;
        }

        // get main game class

        public JaysJourneyMain getGame()
        {
            return this.stateManager.getGame();
        }

        // init state

        public void initState()
        {
            initialize();
        }

        // started state

        public void started()
        {
            this.counter = 0; // 10 frames delay
            onEnterState();
        }

        /**
         * ABSTRACT METHODS
         * */

        public abstract void initialize();
        public abstract void update(GameTime gameTime);
        public abstract void draw(GameTime gameTime);
        public abstract void onEnterState();
    }
}
